import Vue from 'vue'
import VueRouter from 'vue-router'
import Cookies from 'js-cookie';
import {Toast} from 'vant';
import store from '../store'
import httpRequest from "@/api/httpRequest";

Vue.use(VueRouter)
import Home from '@/views/home.vue'
import {commit} from "lodash/seq";
// import TopBar from "./components/index/TopBar";

// const index = new VueRouter({
const routes = [{
    path: '/',
    redirect: 'share'
},
    //=============================================去分享相关子页面============================================
    {
        path: '/page',
        name: '短视频',
        component: () => import('@/components/index/VideoList.vue')
    },
    {
        path: '/article',
        name: '博客',
        component: () => import('@/components/index/Article')
    },
    {
        path: '/search',
        name: '搜索页',
        component: () => import('@/views/share/search')
    },
    {
        path: '/subscribe',
        name: '订阅',
        component: () => import('@/views/share/subscribe')
    },
    {
        path: '/publish',
        name: '发布',
        component: () => import('@/views/share/pubilsh')
    },
    {
        path: '/trends',
        name: '动态',
        component: () => import('@/views/share/trends/index')
    },
    {
        path: '/trendsDetail',
        name: '动态详情',
        component: () => import('@/views/share/trends/detailIndex')
    },
    {
        path: '/articleDetail',
        name: '文章详情',
        component: () => import('@/views/share/article/index')
    },
    //===========================================================我的相关子页面=================================
    {
        path: '/personalPage',
        name: '个人主页',
        component: () => import('@/views/my/personal/index')
    },
    {
        path: '/visitPersonal',
        name: '访问个人主页',
        component: () => import('@/views/my/personal/visitPersonal')
    },
    {
        path: '/detectorManagement',
        name: '检测人管理',
        component: () => import('@/views/my/detectorManagement/index')
    },
    {
        path: '/addFriend',
        name: '添加好友',
        component: () => import('@/views/my/personal/addFriend')
    },
    {
        path: '/addDetector',
        name: '新增检测人',
        component: () => import('@/views/my/detectorManagement/addDetector')
    },
    {
        path: '/setting',
        name: '设置',
        component: () => import('@/views/my/setting/index')
    },
    {
        path: '/userServiceAgreement',
        name: '用户服务协议',
        component: () => import('@/views/my/setting/userServiceAgreement')
    },
    {
        path: '/privacyTermsService',
        name: '隐私协议条款',
        component: () => import('@/views/my/setting/privacyTermsService')
    },
    {
        path: '/loginPassword',
        name: '修改登录密码',
        component: () => import('@/views/my/setting/loginPassword')
    },
    {
        path: '/about',
        name: '关于百合医',
        component: () => import('@/views/my/setting/about')
    },
    {
        path: '/personInfo',
        name: '个人信息',
        component: () => import('@/views/my/personal/personInfo')
    },
    {
        path: '/accountOrSecurity',
        name: '账号与安全',
        component: () => import('@/views/my/setting/accountOrSecurity')
    },
    {
        path: '/freeBack',
        name: '意见反馈',
        component: () => import('@/views/my/setting/freeBack')
    },
    {
        path: '/addressManagement',
        name: '地址管理',
        component: () => import('@/views/my/setting/addressManagement')
    },
    // addAddress
    {
        path: '/addAddress',
        name: '新增地址',
        component: () => import('@/views/my/setting/addAddress')
    },
    {
        path: '/healthRecords',
        name: '健康档案',
        component: () => import('@/views/my/health/healthRecords')
    },
    {
        path: '/medicalRecords',
        name: '医疗记录',
        component: () => import('@/views/my/health/medicalRecords')
    },
    {
        path: '/dietaryRecords',
        name: '饮食记录',
        component: () => import('@/views/my/health/dietaryRecords')
    },
    {
        path: '/settingPhone',
        name: '更换手机号',
        component: () => import('@/views/my/setting/settingPhone')
    },
    {
        path: '/addPhone',
        name: '检测人手机号',
        component: () => import('@/views/my/detectorManagement/addPhone')
    },
    //亲友管理页面
    {
        path: '/addFamilyFriend',
        name: '新增(编辑)亲友',
        component: () => import('@/views/my/familyFriendManagement/addFamilyFriend')
    },
    {
        path: '/familyFriendList',
        name: '亲友管理',
        component: () => import('@/views/my/familyFriendManagement/index')
    },
    {
        path: '/addFamilyFriendPhone',
        name: '亲友手机号',
        component: () => import('@/views/my/familyFriendManagement/addPhone')
    },
    //================================商城相关页面路由===================================
    {
        path: '/searchShopping',
        name: '搜索',
        component: () => import('@/views/shopping/search/index')
    },
    {
        path: '/detail',
        name: '商品详情',
        component: () => import('@/views/shopping/detail/index')
    },
    {
        path: '/writeOrder',
        name: '填写订单',
        component: () => import('@/views/shopping/pay/index')
    },
    {
        path: '/payLoading',
        name: '支付跳转页',
        component: () => import('@/views/shopping/payLoding')
    },
    {
        path: '/payStatus',
        name: '付款状态',
        component: () => import('@/views/shopping/payStatus/index')
    },
    {
        path: '/order',
        name: '查看订单',
        component: () => import('@/views/shopping/order/index')
    },
    {
        path: '/orderDetail',
        name: '订单详情',
        component: () => import('@/views/shopping/order/orderDetail')
    },
    {
        path: '/payComplete',
        name: 'H5-支付完成',
        component: () => import('@/views/shopping/payComponent')
    },
    //=====================================去聊天相关页面路由================================
    {
        path: '/kzList',
        name: '去咨询-首页',
        component: () => import('@/views/chat/customer_consultation_list'),
        meta: {title: '客服咨询'}
    },
    {
        path: '/chat',
        name: '聊天详情-好友',
        component: () => import('@/views/chat/customer_consulation_chat'),
    },
    {
        path: '/historyChat',
        name: '历史记录-聊天',
        component: () => import('@/views/chat/customer_consulation_history_chat')
    },
    {
        path: '/chatOffic',
        name: '店铺客服',
        component: () => import('@/views/chat/customer_consulation_chat_offic'),
        meta: {title: '店铺客服'}
    },
    {
        path: '/historySearch',
        name: '去咨询-历史搜索页',
        component: () => import('@/views/chat/historySearch')
    },
    {
        path: '/bhyOffic',
        name: '百合医客服',
        component: () => import('@/views/chat/customer_consulation_chat_bhy_offic')
    },
    {
        path: '/shopList',
        name: '商家客服消息列表',
        component: () => import('@/views/chat/customer_consultation_shop_list')
    },
    {
        path: '/shopchat',
        name: '商家客服消息-总',
        component: () => import('@/views/chat/customer_consulation_shop_chat')
    },
    {
        path: "/",
        name: 'home',
        component: Home,
        children: [
            {
                path: '/share',
                name: '去分享',
                component: () => import('@/views/share'),

            },
            {
                path: '/shopping',
                name: '去治疗',
                component: () => import('@/views/shopping/Shopping.vue')
            },
            {
                path: '/my',
                name: '我的',
                component: () => import('@/views/my')
            },
            // {
            //     path: '/chat',
            //     name: '去咨询',
            //     component: () => import('@/views/shopping/Shopping.vue')
            // },
        ]
    },

    // =====================================我的二维码==============================================
    {
        path: '/myQrcode',
        name: '我的二维码',
        component: () => import('@/views/my/myQrCode/myQrcode')
    },
    {
        path: '/addFrendOrRelatives',
        name: '添加',
        component: () => import('@/views/my/myQrCode/addFrend')
    },
    {
        path: '/checkLoading',
        name: '添加好友',
        component: () => import('@/views/my/myQrCode/checkLoading')
    },
    {
        path: '/addRelation',
        name: '亲友-选择关系',
        component: () => import('@/views/my/familyFriendManagement/addRelation')
    },
    {
        path: '/isFriend',
        name: '添加好友',
        component: () => import('@/views/my/myQrCode/isFriend')
    },
]
// })
const router = new VueRouter({
    routes
})

router.beforeEach(async (to, from, next) => {
    // console.log('----------beforeEach ------')
    // await store.dispatch('getUserInfo')
    // console.log('userInfo',)
    // await store.dispatch('loginChat', store.state.userInfo)
    //初始化 子系统即时通讯
    // init(userInfo) {
    // console.log('子系统的用户信息', store.state.childrenUserInfo)
    // commit("setUserState",this.$enums.USER_STATE.FREE);
    // commit("initStore");
    // this.$forceUpdate()
    // this.$wsApi.createWebSocket('wss://wechat.yasee.com.cn:8878/im', userInfo.id); //初始化websocket链接
    // sessionStorage.setItem("isWsApi", 1);
    // this.$wsApi.onopen(() => {
    //     // this.pullUnreadMessage();
    // });
    // this.$wsApi.onmessage((cmd, msgInfo) => {
    //     if (cmd == 2) {
    // 异地登录，强制下线
    // this.$store.commit('setChildrenFlag', 0);
    // this.$message.error("您已在其他地方登陆，将被强制下线");
    // setTimeout(() => {
    //   location.href = "/";
    // }, 1000)
    // } else if (cmd == 3) {
    //     // 插入私聊消息
    //     this.handlePrivateMessage(msgInfo);
    // }
    // else if (cmd == 4) {
    //   // 插入群聊消息
    //   this.handleGroupMessage(msgInfo);
    // }
    // })
    // }
    next()
})

export default router
